<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined( '_JEXEC' ) or die( 'Restricted access' );

class iJoomla_SurveysControllerPrevsurvey extends iJoomla_SurveysController{
	
	function __construct() {	  
		parent::__construct();
		// Register Extra tasks	
		$this->registerTask('', 'prevsurvey');
		$this->registerTask('back', 'back');
		$this->registerTask('next', 'nextPage');
	}			
	
	function prevsurvey(){		
		JRequest::setVar('view', 'Prevsurvey');	
		parent::display();
	}
	
	function back(){		
		$model = $this->getModel('prevsurvey');						
				
		$survey_id = JRequest::getVar("survey_id", "", "post");
		$current_page_id = JRequest::getVar("current_page_id", "", "post");	
		$page_details = $model->getPageDetails($current_page_id);
		$page_order = $page_details["0"]["ordering"];
		$pages = $model->getPrevNextPage($survey_id, $current_page_id, $page_order);		
		$survey_id_alias = JRequest::getVar("survey_id_alias", "", "post");
		$prev_page = $pages["prev"];
		$next_page = $pages["next"];			
		$action = 'index.php?option=com_surveys&controller=prevsurvey&id='.$survey_id_alias.'&page='.$prev_page;
		$_SESSION["view_result"] = "true";
		$this->setRedirect($action);
	}
	
	function nextPage(){
		$model = $this->getModel('prevsurvey');						
				
		$survey_id = JRequest::getVar("survey_id", "", "post");
		$current_page_id = JRequest::getVar("current_page_id", "", "post");	
		$page_details = $model->getPageDetails($current_page_id);
		$page_order = $page_details["0"]["ordering"];
		$pages = $model->getPrevNextPage($survey_id, $current_page_id, $page_order);		
		$survey_id_alias = JRequest::getVar("survey_id_alias", "", "post");
		$prev_page = $pages["prev"];
		$next_page = $pages["next"];			
		$action = 'index.php?option=com_surveys&controller=prevsurvey&id='.$survey_id_alias.'&page='.$next_page;
		$_SESSION["view_result"] = "true";
		$this->setRedirect($action);
	}
}

?>